package com.molin.edu.info.manager.dao;

import com.molin.edu.info.manager.domain.Student;

import java.util.ArrayList;

/*
 * 操作数据模型，不太关心数据是否合理。
 * 逻辑简洁明了，动作干净利索。*/
public abstract class BaseStudentDao implements BaseStudentDaoInter{

    public static ArrayList<Student> studentArrayList = new ArrayList<>();
    static {
//        静态代码块，初始化学生信息，方便测试。
        Student st1=new Student("molin001","张三",23,"1994-10-11");
        Student st2=new Student("molin002","李四",26,"1990-12-13");
        studentArrayList.add(st1);
        studentArrayList.add(st2);
    }
    public final boolean addStudent(Student student) {
        return studentArrayList.add(student);
    }

    public final ArrayList<Student> showStudentInfo() {
        return studentArrayList;
    }

    public final ArrayList<Student> findAll() {
        return studentArrayList;
    }

    public final boolean dropStudentInfo(Student st) {
        return studentArrayList.remove(st);
    }

    public final Student fetchOne(String id) {
        Student student = new Student();
        for (int i = 0; i < studentArrayList.size(); i++) {
            if (studentArrayList.get(i).getId().equals(id)) {
                student = studentArrayList.get(i);
            }
        }
        return student;
    }

    public abstract boolean modifyStudent(Student st);
}
